package com.th.coupon.controller;

import com.alibaba.fastjson.JSON;
import com.th.coupon.common.exception.BaseCloudException;
import com.th.coupon.common.vo.SettlementInfo;
import com.th.coupon.executor.ExecuteManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 结算服务控制器
 * @author 涂航
 */
@RestController
@Slf4j
public class SettlementController {

    /**
     * 规则执行结算规则
     */
    private final ExecuteManager executeManager;

    @Autowired
    public SettlementController(ExecuteManager executeManager) {
        this.executeManager = executeManager;
    }

    /**
     * 优惠卷结算功能
     * url(127.0.0.1:10011/discount/coupon-settlement/settlement/compute) 网关
     * @param settlementInfo
     * @return
     * @throws BaseCloudException
     */
    @PostMapping("/settlement/compute")
    public SettlementInfo computeRule(@RequestBody SettlementInfo settlementInfo) throws BaseCloudException {
        log.info("settlement : {}", JSON.toJSONString(settlementInfo));
        return executeManager.computeRule(settlementInfo);
    }


}
